﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlServerCe;
using System.Configuration;

namespace ProjectoPV_ESW.Account.Ementa
{
    /// <summary>
    /// Classe desenvolvida por Mário Pereira.
    /// </summary>
    public partial class VerEscolhasDePrato : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                DiaEmQuestao= (DateTime)Session["DataDiaDiaEscolar"];
            }
            catch (Exception)
            {
                Response.Redirect("SeleccionarDiaEscolhas.aspx");
            }

            string selectCommand = "SELECT Nome, NomePrato ";
            selectCommand += "FROM Crianca, EscolhaPrato, Prato, DiaEscolar ";
            selectCommand+="WHERE Crianca_CriancaId=CriancaId AND DiaEscolarId=DiaEscolar_DiaEscolarId AND PratoId=Prato_PratoId AND Dia=@dia";
            string connectionStringJardim = ConfigurationManager.ConnectionStrings["JardimEntitiesString"].ConnectionString;
            SqlCeConnection conn = new SqlCeConnection(connectionStringJardim);
            SqlCeCommand command = new SqlCeCommand(selectCommand, conn);
            command.Parameters.AddWithValue("@dia", DiaEmQuestao);
            SqlCeDataReader reader;
            string resultados = "";
            try
            {
                conn.Open();
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    resultados += reader["Nome"].ToString() + " - " + reader["NomePrato"].ToString() + "\n";
                }
                this.TextBox1.Text = resultados;
            }
            catch (Exception ex)
            {
                LabelErro.Text = ex.Source + "-" + ex.Message;
            }
            finally
            {
                conn.Close();
            }

        }
        public DateTime DiaEmQuestao { get; set; }
    }
}